﻿using VisionCloud.Domain.ModelAttribute;

namespace VisionCloud.Domain.DtoModel.Ms
{
    /// <summary>
    /// 分页器
    /// </summary>
    public class PagerDto
    {
        /// <summary>
        /// 排序字段 ,如果有多个用,分隔
        /// </summary>
        public string OrderBy { get; set; }

        /// <summary>
        /// 升序或降序排序
        /// </summary>
        [AscDesc]
        public string AscDesc { get; set; }

        /// <summary>
        /// 数据总量
        /// </summary>
        public int Total { get; set; }

        private int pageIndex = 0;

        /// <summary>
        ///  页数
        /// </summary>
        public int PageIndex
        {
            get
            {
                if (pageIndex <= 0)
                {
                    return 1;
                }
                else
                {
                    return pageIndex;
                }
            }
            set
            {
                if (value >= 1)
                {
                    pageIndex = value;
                }
                else
                {
                    pageIndex = 1;
                }
            }
        }

        /// <summary>
        /// 当前页数据开始索引
        /// </summary>
        public int PageDataBeginIndex
        {
            get
            {
                //return PageSize * (PageIndex - 1) + PageSize;
                return PageSize * (PageIndex - 1);
            }
        }

        private int pageSize = 0;

        /// <summary>
        /// 分页大小
        /// </summary>
        public int PageSize
        {
            get
            {
                if (pageSize <= 0)
                {
                    return 20;
                }
                else
                {
                    return pageSize;
                }
            }
            set
            {
                if (value > 0)
                {
                    pageSize = value;
                }
                else
                {
                    pageSize = 20;
                }
            }
        }

        /// <summary>
        /// 总共的页数
        /// </summary>
        public int PageTotal
        {
            get
            {
                return Total / PageSize + (Total % PageSize > 0 ? 1 : 0);
            }
        }

        /// <summary>
        /// 当前页数据
        /// </summary>
        public object Result { get; set; }
    }
}